library(ggplot2)
library(foreign)

#####
# Figure 1
#####
h <- read.csv("/Users/jrthornton/Desktop/replication/satis_binary hist by mode.csv")

h$type<-reorder(h$type,h$type.order)

lab<-c("0%","25%","50%","75%")

p<-ggplot(data=h, aes(x=type, y=percent)) +
  geom_bar(stat="identity", fill="grey85", colour="black",size=.3) #+   geom_hline(yintercept=0,size=.33)
dev.new(width=3.5,height=3.5)
dev.size()

p + facet_grid(year~mode) +
 	theme_linedraw() +
 	theme(panel.grid.minor = element_blank()) +
	theme(panel.grid.major.x = element_blank()) +
	theme(panel.grid.major.y = element_line(colour = "grey90",size=0.5, linetype="solid")) + 
	scale_y_continuous(expand = c(0.05, 0.05) ,breaks=c(0,25,50,75), labels=lab) +  
	theme(panel.border = element_rect(fill=NA, colour = "black", size=.667)) +
    theme(strip.background = element_rect(color="white",fill="white",size=1)) + 
  	theme(strip.text = element_text(color = 'black')) + 	
  	ylab(" ") + xlab("Satisfaction with Democracy")
  	
  	
 ####
 # Figure f.1: Satisfaction (four categories) by mode
 ####
 h2 <- read.csv("/Users/jrthornton/Desktop/replication/satisfaction by mode.csv")

h2 $type<-reorder(h$type,h$type.order)

lab<-c("0%","20%","40%","60%")

p<-ggplot(data= h2, aes(x=satisfaction, y=percent)) +
  geom_bar(stat="identity", fill="grey85", colour="black",size=.3) #+   geom_hline(yintercept=0,size=.33)
dev.new(width=3.5,height=3.5)
dev.size()

p + facet_grid(year~mode) +
 	theme_linedraw() +
 	theme(panel.grid.minor = element_blank()) +
	theme(panel.grid.major.x = element_blank()) +
	theme(panel.grid.major.y = element_line(colour = "grey90",size=0.5, linetype="solid")) + 
	scale_y_continuous(expand = c(0.05, 0.05) ,breaks=c(0,.2,.4,.6), labels=lab) +  
	theme(panel.border = element_rect(fill=NA, colour = "black", size=.667)) +
    theme(strip.background = element_rect(color="white",fill="white",size=1)) + 
  	theme(strip.text = element_text(color = 'black')) + 	
  	ylab(" ") + xlab("Satisfaction with Democracy")

  	

		
		
###
# Figure f.2: Ordered logig predicted values
###

dev.new(width=6.5,height=3)
dev.size()


x<-read.csv("/Users/jrthornton/Desktop/replication/ologit_pred.csv")

x$Satisfaction<-reorder(x$s,x$s.order)


ggplot(x, aes(x=mode, y=prob,group= Satisfaction,fill=Satisfaction)) +
    geom_line( aes(color=Satisfaction,linetype= Satisfaction)) +
	geom_linerange(mapping=aes(x= mode,ymin=lower,ymax=upper,color= Satisfaction),size=.33) +
	geom_point(aes(y= prob,group= Satisfaction,shape= Satisfaction,color= Satisfaction,fill= Satisfaction),size=1.667) + 
    facet_wrap(~model) + 
    ylab("Probability") + xlab("Mode") + 
  	theme_linedraw() +
	theme(panel.border = element_rect(fill=NA, colour = "black", size=.667)) +
    theme(strip.background = element_rect(color="white",fill="white",size=1)) + 
  	theme(strip.text = element_text(color = 'black')) + 			
  	theme(panel.grid.minor = element_blank()) +
	theme(panel.grid.major.x = element_blank()) +
  	theme(axis.ticks.x = element_blank())
  	
